﻿namespace WP7Contrib.View.Controls.Tests
{
    using Microsoft.Silverlight.Testing;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using WP7Contrib.Logging;
    using System.Windows.Controls;
    using System;

    /// <summary>
    /// Unit tests for GridUtils.
    /// </summary>
    /// <remarks>
    /// http://msdn.microsoft.com/en-us/library/system.windows.gridunittype.aspx
    /// </remarks>
    [TestClass]
    public class GridUtilsTests : SilverlightTest
    {
        #region "Row definition tests"
        [TestMethod]
        [ExpectedException(typeof(FormatException), "Row definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Row_Definition_Containing_Alpabhets_Only()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "o");
        }

        [TestMethod]
        [ExpectedException(typeof(FormatException), "Row definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Row_Definition_Containing_Combination_Of_Alpabhets_And_Numerals()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "o0");
        }

        [TestMethod]
        [ExpectedException(typeof(FormatException), "Row definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Row_Definition_Containing_Combination_Of_Non_Alpha_Numerals()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "$%*_");
        }
        
        [TestMethod]
        [ExpectedException(typeof(FormatException), "Row definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Row_Definition_Containing_Incorrect_GridUnitType_Auto()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "Auttoo");
        }

        [TestMethod]
        [ExpectedException(typeof(FormatException), "Row definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Row_Definition_Containing_Incorrect_GridUnitType_Star()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "_*");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException), "Row definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Row_Definition_Containing_GridUnitType_With_Negative_Pixel_Value()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "-2");
        }

        [TestMethod]
        [ExpectedException(typeof(FormatException), "Row definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Row_Definition_Containing_GridUnitType_With_Multiple_Auto()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "AutoAuto");
        }

        [TestMethod]
        public void Row_Definition_Containing_GridUnitType_With_Large_Pixel_Value()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "2348273498237429384.000000000000");
        }

        [TestMethod]
        public void Row_Definition_Containing_GridUnitType_With_Pixel_Value_Less_Than_Zero()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "0.56");
        }

        [TestMethod]
        public void Row_Definition_Containing_GridUnitType_Auto()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "Auto");
        }

        [TestMethod]
        public void Row_Definition_Containing_GridUnitType_Star()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "*");
        }

        [TestMethod]
        public void Row_Definition_Containing_GridUnitType_Star_And_Number()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "*0.35");
        }

        [TestMethod]
        public void Row_Definition_Containing_GridUnitType_Number_And_Star()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "0.45*");
        }

        [TestMethod]
        public void Row_Definition_Containing_GridUnitType_With_Multiple_Star()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetRowDefinitions(sampleGrid, "**");
        }       
        #endregion

        #region "Column definition tests"
        [TestMethod]
        [ExpectedException(typeof(FormatException), "Column definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Column_Definition_Containing_Alpabhets_Only()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "o");
        }

        [TestMethod]
        [ExpectedException(typeof(FormatException), "Column definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Column_Definition_Containing_Combination_Of_Alpabhets_And_Numerals()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "o0");
        }

        [TestMethod]
        [ExpectedException(typeof(FormatException), "Column definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Column_Definition_Containing_Combination_Of_Non_Alpha_Numerals()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "$%*_");
        }

        
        [TestMethod]
        [ExpectedException(typeof(FormatException), "Column definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Column_Definition_Containing_Incorrect_GridUnitType_Auto()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "Auttoo");
        }

        [TestMethod]
        [ExpectedException(typeof(FormatException), "Column definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Column_Definition_Containing_Incorrect_GridUnitType_Star()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "_*");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException), "Column definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Column_Definition_Containing_GridUnitType_With_Negative_Pixel_Value()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "-2");
        }

        [TestMethod]
        [ExpectedException(typeof(FormatException), "Column definition can only have GridUnitType - 'Auto', 'Star' or 'Pixels'")]
        public void Throw_Exception_For_Column_Definition_Containing_GridUnitType_With_Multiple_Auto()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "AutoAuto");
        }

        [TestMethod]
        public void Column_Definition_Containing_GridUnitType_With_Large_Pixel_Value()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "2348273498237429384.000000000000");
        }

        [TestMethod]
        public void Column_Definition_Containing_GridUnitType_With_Pixel_Value_Less_Than_Zero()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "0.56");
        }

        [TestMethod]
        public void Column_Definition_Containing_GridUnitType_Auto()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "Auto");
        }

        [TestMethod]
        public void Column_Definition_Containing_GridUnitType_Star()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "*");
        }

        [TestMethod]
        public void Column_Definition_Containing_GridUnitType_Star_And_Number()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "*0.35");
        }

        [TestMethod]
        public void Column_Definition_Containing_GridUnitType_Number_And_Star()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "0.45*");
        }

        [TestMethod]
        public void Column_Definition_Containing_GridUnitType_With_Multiple_Star()
        {
            // Log...
            var log = new DebugLog();
            Grid sampleGrid = new Grid();
            GridUtils.SetColumnDefinitions(sampleGrid, "**");
        }       
        #endregion
    }
}
